﻿#pragma once
#include "protocolOption.h"
#include "protocol.h"

class ProtocolBuilder {
public:
	ProtocolBuilder();
	// 设置协议格式
	void setProtocolOption(std::shared_ptr<ProtocolOption> option);

	// 设置特定索引的首部字段的值
    void setHeaderField(int64_t index, const OptionValue& value);

	// 设置协议数据内容
    std::shared_ptr<Protocol> buildWithHeaderAndData(void* data,int64_t size);

    // build with plain buffer

    std::shared_ptr<Protocol> buildFromRawData(void* data, int64_t size);

    void updateProtocolData(std::shared_ptr<Protocol> protocol,  void* data, int64_t size);

private:
	std::shared_ptr<ProtocolOption> _option;

	// 头标记的个数
    int64_t _length;
	// 头标记的启始位置
    std::deque<int64_t> _sum;
	// 头标记缓冲区
	std::unique_ptr<unsigned char[]> _head;
};
